package com.gssuren.demo.service.impl;

import com.gssuren.demo.dao.UserDao;
import com.gssuren.demo.model.User;
import com.gssuren.demo.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class UserServiceImpy implements UserService {
    @Resource
    private UserDao userDao;

    @Override
    public boolean addUser(User user) {
        boolean flag = false;
        try {
            userDao.insert(user);
            flag = true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }

    @Override
    public boolean updateUser(User user) {
        boolean flag = false;
        try {
            userDao.updateByPrimaryKey(user);
            flag = true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }

    @Override
    public boolean deleteUser(int id) {
        boolean flag = false;
        try {
            userDao.deleteByPrimaryKey(id);
            flag = true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }

    @Override
    public List<User> findUserByName(String memberName) {
        List<User> users = new ArrayList<>();
        try {
            users = userDao.selectByName(memberName);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return users;
    }

}